package tw.edu.tku.im.maze.database;
import java.io.FileWriter;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Calendar;



public class Server {

   public static void main(String[] args) throws IOException {
         ServerSocket server;
         server = new ServerSocket(3333);
         System.out.println("接受連線中");
         while (true) {
            
            Socket socket;
            try {
               socket = server.accept();
               final Calendar time = Calendar.getInstance();
               final StringBuilder msg = new StringBuilder();
               msg.append('[')
                  .append(time.get(Calendar.YEAR)).append('/')
                  .append(time.get(Calendar.MONTH)).append('/')
                  .append(time.get(Calendar.DAY_OF_MONTH)).append(' ')
                  .append(time.get(Calendar.HOUR)).append(':')
                  .append(time.get(Calendar.MINUTE)).append(':')
                  .append(time.get(Calendar.SECOND)).append(']')
                  .append("Accepting connection from ")
                  .append(socket.getInetAddress()).append(':')
                  .append(socket.getPort());
               System.err.println(msg);
               Processor processor = new Processor(socket);
               processor.start();
            } catch (IOException e) {
               e.printStackTrace();
               FileWriter fw=new FileWriter("errLog.txt",true);
               fw.write(e.toString());
               fw.close();        
            }
         }
   }
   

}
